home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-05-07 | 1.1 KB | 38 lines | [TEXT/McSk] |
- ( Sleeve of Erastothanes for version 0.6 )
- ( optomized for Pocket Forth with inline machine code )
- ( based on a letter by Don Colburn in DDJ #83 )
- forget task : task ; decimal 0 28 +md !
-
- ( tenth second timer )
- : START ( -- d ) 362 0 dl@ ; ( get 'ticks' )
- : T. ( sec -- ) s>d <# # 46 hold #S #> type ; ( print sec.tenths )
- : STOP ( d -- ) start cr 2swap dnegate d+ drop 6 / t. ." sec." ;
-
- ( compile machine code inline routines )
- : R+ ( n -- n+r ) ( add the loop index to the number on the stack )
- ,$ 3017 ,$ D156 ; macro ( move.w [rs],d0 add.w d0,[ps] )
- : 0RC! ( -- ) ( clear the byte pointed to by the index loop )
- ,$ 3017 ,$ 4233 ,$ 0 ; macro ( move.w [rs],d0 clr.b 0[bp,d0] )
-
- 8190 constant SIZE
- variable FLAGS size allot
-
- : PRIME flags size 1 fill
- 0 size 0 DO
- flags r+ c@ IF
- 3 r+ r+ dup r+ size < IF
- size flags + over r+ flags +
- DO 0rc! dup +LOOP
- THEN drop 1+
- THEN
- LOOP . ." primes" cr ;
-
- : SIEVE page ." The Sieve of Erastothanes" decimal
- cr start 10 BEGIN prime 1- DUP 0= UNTIL DROP stop
- beep cr ." Not too shabby, eh?" cr ;
-
- 0 28 +md !
- sieve
-
-
-